/**   
 * @Title: ShengfurenjiuRecordDetailAct.java 
 * @Package com.esun.rabbit2.viewer.mainact.mylotteryact.lotteryrecord 
 * @Description: 胜负任九购彩记录方案详情
 * @author: City Jiangsy@500wan.com   
 * @date: 2012-1-11 上午10:28:28  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.mylotteryact.lotteryrecord;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.model.HemaiDetailInfo;
import com.esun.model.ShengFuRenJiuDetailInfo;
import com.esun.model.ShengfuRenjiuTouzhuInfo;
import com.esun.model.UserInfo;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.rabbit2.communicaters.CheDanCommunicater;
import com.esun.rabbit2.communicaters.GetUserIconCommunicater;
import com.esun.rabbit2.communicaters.lotteryrecord.GetRenjiuShengfuRecordDetailCommunicater;
import com.esun.rabbit2.viewer.mainact.OptionAct;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.HelpAct;
import com.esun.ui.R;
import com.esun.util.ShowZhanji;
import com.esun.util.ViewerUtil;
import com.esun.util.img.ImageUtils;
import com.esun.util.img.db.ImageDB;
import com.esun.util.log.EDebug;

/**
 * @ClassName: ShengfurenjiuRecordDetailAct
 * @Description: 胜负任九购彩记录方案详情
 * @author: City Jiangsy@500wan.com
 * @date: 2012-1-11 上午10:28:28
 * 
 */
public class ShengfurenjiuRecordDetailAct extends Activity implements OnClickListener {
	private TextView tvTerm;
	private TextView tvTime;
	private TextView tvProId;
	private TextView tvFaqiren;
	private TextView tvHitCount;
	private TextView tvHitMoney;
	private TextView tvAllMoney;
	private TextView tvMultiple;
	private TextView tvAllCount;
	private TextView tvEachMoney;
	private TextView tvBaodiMoney;
	private TextView tvTicheng;
	private TextView tvIssuc;
	private TextView tvJindu;
	private TextView tvTitle;
	private ImageView imageFaqiren;
	private TextView tvLotteryState;
	private TextView tvWinMoney;

	private LinearLayout linearZhanji;
	private LinearLayout linearContent;
	private LinearLayout linearLayOutZhanji;

	private RelativeLayout relativeOpenCode;
	private TextView tvOpenCode;

	private ImageButton btnCancel;
	private Button btnCheDan;
	private ProgressDialog progress;

	private static final String NO_DATA = "--";

	private GetRenjiuShengfuRecordDetailCommunicater detailCommunicater;
	private GetUserIconCommunicater getUserIconCommunicater;
	private CheDanCommunicater cheDanCommunicater;

	private Handler handlerHemaiDetail;

	private final int GET_DETAIL_SUCCEED = 1001;
	private final int GET_DETAIL_FAIL = 1002;
	private final int CHEDAN_SUCCEED = 1003; // 撤单通信成功
	private final int CHEDAN_FAIL = 1004;// 撤单通信失败
	private final int REPLACE_IMAGE = 1006;
	private final int GET_ICONNAME_SUCCEED = 1007;
	private final int GET_ICONNAME_FAIL = 1008;
	private final String STAR = "*";
	private final String NOT_CHOOSE = "未投注";
	private String lotId = "";
	private String strfaqiren = "";
	private String showId = "";
	private String getManey = "";
	private String playId = "";
	private String lotName = "";
	private String id = "";
	private String expect = "";
	private String playName = "";
	private String uid = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.shengfurenjiu_record_detail_act);
		initData();
		initUi();
		initHandler();
	}

	private void initHandler() {
		handlerHemaiDetail = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case REPLACE_IMAGE:
					Bitmap bm = (Bitmap) msg.obj;
					imageFaqiren.setImageBitmap(bm);

					break;
				case GET_DETAIL_SUCCEED:
					detailCommunicater.updateInfo();
					updateTvContent();
					progress.dismiss();
					break;

				case GET_DETAIL_FAIL:
					progress.dismiss();
					
					//ViewerUtil.showTipDialog(ShengfurenjiuRecordDetailAct.this, detailCommunicater.getServerMsg(), false);
					Toast.makeText(ShengfurenjiuRecordDetailAct.this, detailCommunicater.getServerMsg(), Toast.LENGTH_SHORT).show();
					break;

				case Config.CONNECTION_FAIL:
					progress.dismiss();
					//ViewerUtil.showTipDialog(ShengfurenjiuRecordDetailAct.this, Language.STR_CONNECTIONFAIL, false);
					Toast.makeText(ShengfurenjiuRecordDetailAct.this, Language.STR_CONNECTIONFAIL, Toast.LENGTH_SHORT).show();
					break;

				case GET_ICONNAME_SUCCEED:
					getAvatar();
					break;

				case GET_ICONNAME_FAIL:
					EDebug.o(ShengfurenjiuRecordDetailAct.this, "get icon name fail");
					break;

				case CHEDAN_SUCCEED:
					EDebug.o(this, "撤单成功");
					UserInfo.getUserInfo().setUserBalance(cheDanCommunicater.getMoney());
					ViewerUtil.showTipDialog(ShengfurenjiuRecordDetailAct.this, Language.MSG_REMOVE_SUCCEED, false);
					break;

				case CHEDAN_FAIL:
					EDebug.o(this, "撤单失败");
					String serverMsg = (String) msg.obj;
					ViewerUtil.showTipDialog(ShengfurenjiuRecordDetailAct.this, serverMsg, false);
					break;

				default:
					break;
				}
			}

		};

	}

	private void updateTvContent() {
		ShengFuRenJiuDetailInfo shengfuinfo = ShengFuRenJiuDetailInfo.getInfo();
		strfaqiren = shengfuinfo.getUserName();
		expect = shengfuinfo.getExpect();
		playName = shengfuinfo.getPlayname();
		lotName = shengfuinfo.getLotName();
		showId = shengfuinfo.getProid();
		playId = shengfuinfo.getPlayID();

		tvTerm.setText("方案详情");
		tvProId.setText(showId);
		tvTime.setText(shengfuinfo.getAddTime());
		tvTitle.setText(lotName + Language.POPLOTTERYTIP_DI + expect + Language.POPLOTTERYTIP_QI + playName);
		tvHitCount.setText(shengfuinfo.getLotteryCount());
		tvHitCount.setTextColor(getResources().getColor(R.color.kjxx_blue));
		tvHitMoney.setText(Language.POPLOTTERYTIP_RMB + shengfuinfo.getLotteryMoeny());
		tvHitMoney.setTextColor(getResources().getColor(R.color.kjxx_red));
		tvAllMoney.setText(Language.POPLOTTERYTIP_RMB + shengfuinfo.getAllMoney());
		tvAllMoney.setTextColor(getResources().getColor(R.color.kjxx_red));
		tvMultiple.setText(shengfuinfo.getBeiShu());
		tvAllCount.setText(shengfuinfo.getAllNumber());
		tvEachMoney.setText(Language.POPLOTTERYTIP_RMB + shengfuinfo.getOneMoney());
		tvEachMoney.setTextColor(getResources().getColor(R.color.kjxx_red));
		tvBaodiMoney.setText(Language.POPLOTTERYTIP_RMB + shengfuinfo.getBaoDiMoney());
		tvBaodiMoney.setTextColor(getResources().getColor(R.color.kjxx_red));
		tvTicheng.setText(shengfuinfo.getTiCheng() + Config.PERCENT);
		if (shengfuinfo.getIssuc().equals(Config.NUM1)) {
			tvIssuc.setText(Language.POPLOTTERYTIP_ISSUCYET);
		} else {
			tvIssuc.setText(Language.POPLOTTERYTIP_NOTISSUC);
		}
		tvJindu.setText(shengfuinfo.getJinDu() + Config.PERCENT);

		// 是否显示撤单按钮
		if (shengfuinfo.getIshm().equals(Config.NUM1)) {
			int baodi = Integer.valueOf(shengfuinfo.getBaodi());
			int jindu = Integer.valueOf(shengfuinfo.getJinDu());
			if (baodi + jindu < 50) {
				btnCheDan.setVisibility(View.VISIBLE);
			}
		}

		setProjectContent();

		tvFaqiren.setText(strfaqiren);
		threadGetUserIcon(strfaqiren);

		if (shengfuinfo.getLotterystate().equals("0")) {
			tvLotteryState.setText(Language.MSG_DENGDAIKAIJIANG);
		} else if (shengfuinfo.getLotterystate().equals("1")) {
			tvLotteryState.setText("未算奖");
		} else if (shengfuinfo.getLotterystate().equals("2")) {
			tvLotteryState.setText("未中奖");
		} else if (shengfuinfo.getLotterystate().equals("3")) {
			tvLotteryState.setText("未派奖");
		} else if (shengfuinfo.getLotterystate().equals("4")) {
			tvLotteryState.setText("已派奖");
			tvWinMoney.setVisibility(View.VISIBLE);
			tvWinMoney.setText("￥" + getManey);
		}

		if (shengfuinfo.getLotterystate().equals("0")) {
			relativeOpenCode.setVisibility(View.GONE);
		} else {
			relativeOpenCode.setVisibility(View.VISIBLE);
			tvOpenCode.setText(shengfuinfo.getOpencode().replaceAll(Config.COMMA, Config.ONESPACE));

		}
		// 金钻
		String golddiamond = shengfuinfo.getGoldDiamond();
		// 银钻
		String silverdiamond = shengfuinfo.getSilverDiamond();
		// 金星
		String goldstar = shengfuinfo.getGoldStar();
		// 银星
		String silverstar = shengfuinfo.getSilverStar();
		// 金杯
		String goldcup = shengfuinfo.getGoldCup();
		// 战绩显示
		zhanJiShow(golddiamond, silverdiamond, goldstar, silverstar, goldcup);

	}

	// 设置方案内容
	private void setProjectContent() {
		EDebug.o(this, "显示方案内容");

		if (ShengFuRenJiuDetailInfo.getInfo().getFilecode().contains("txt")) {
			EDebug.o(this, "方案内容为txt");
			// 0未上传1已上传
			if (ShengFuRenJiuDetailInfo.getInfo().getIsUpload().equals("1")) {
				EDebug.o(this, "方案已上传");
				if (ShengFuRenJiuDetailInfo.getInfo().getUserName().equals(UserInfo.getUserInfo().getUserName())) {
					Button btnTXT = new Button(ShengfurenjiuRecordDetailAct.this);
					btnTXT.setText("查看上传方案");
					btnTXT.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							Intent intent = new Intent();
							intent.setClass(ShengfurenjiuRecordDetailAct.this, HelpAct.class);
							Bundle bundle = new Bundle();
							bundle.putString("title", "方案内容");
							bundle.putString("havetitle", Config.NUM1);
							if (lotId.equals(Config.SHENGFUCAI)) {
								bundle.putString("url", Config.SHENGFU_TXT_URL + playId + "&pid=" + id);
							} else if (lotId.equals(Config.RENXUANJIU)) {
								bundle.putString("url", Config.RENJIU_TXT_URL + playId + "&pid=" + id);
							}
							EDebug.o(this, bundle.getString("url"));
							startActivity(intent.putExtras(bundle));
						}
					});
					linearContent.addView(btnTXT);
				} else {
					if (ShengFuRenJiuDetailInfo.getInfo().getIsShow().equals(Config.NUM0) || ShengFuRenJiuDetailInfo.getInfo().getIsShow().equals(Config.NUM2)) {
						Button btnTXT = new Button(ShengfurenjiuRecordDetailAct.this);
						btnTXT.setText("查看上传方案");
						btnTXT.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {
								Intent intent = new Intent();
								intent.setClass(ShengfurenjiuRecordDetailAct.this, HelpAct.class);
								Bundle bundle = new Bundle();
								bundle.putString("title", "方案内容");
								bundle.putString("havetitle", Config.NUM1);
								if (lotId.equals(Config.SHENGFUCAI)) {
									bundle.putString("url", Config.SHENGFU_TXT_URL + playId + "&pid=" + id);
								} else if (lotId.equals(Config.RENXUANJIU)) {
									bundle.putString("url", Config.RENJIU_TXT_URL + playId + "&pid=" + id);
								}
								EDebug.o(this, bundle.getString("url"));
								startActivity(intent.putExtras(bundle));
							}
						});
						linearContent.addView(btnTXT);
					} else {
						EDebug.o(this, "截止后公开");
						linearContent.addView(tvForContentTip("截止后公开"));
					}
				}
			} else {
				EDebug.o(this, "方案未上传");
				linearContent.addView(tvForContentTip("方案未上传"));
			}
		} else {
			// 0 完全公开 1 截止后公开 2 仅跟单人可见
			if (ShengFuRenJiuDetailInfo.getInfo().getIsShow().equals(Config.NUM0) || ShengFuRenJiuDetailInfo.getInfo().getIsShow().equals(Config.NUM2)) {
				EDebug.o(this, "方案公开");
				// 显示投注详情
				displayTouZhuInfo();
			} else {
				EDebug.o(this, "截止后公开");
				linearContent.addView(tvForContentTip("截止后公开"));
			}
		}

	}

	private void displayTouZhuInfo() {

		ArrayList<ShengfuRenjiuTouzhuInfo> list = new ArrayList<ShengfuRenjiuTouzhuInfo>();
		list = ShengFuRenJiuDetailInfo.getInfo().getTouZhuInfo();

		// 方案内容
		for (int i = 0; i < list.size(); i++) {

			LinearLayout linear = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.shengfurenjiu_duizhenlist_line, null);

			TextView tvNum = (TextView) linear.findViewById(R.id.shengfurenjiu_line_tv_num);
			TextView tvHomeTeam = (TextView) linear.findViewById(R.id.shengfurenjiu_line_tv_homeTeam);
			TextView tvGuestTeam = (TextView) linear.findViewById(R.id.shengfurenjiu_line_tv_guestTeam);
			TextView tvState = (TextView) linear.findViewById(R.id.shengfurenjiu_line_tv_state);
			TextView tvDan = (TextView) linear.findViewById(R.id.shengfurenjiu_line_tv_dan);
			TextView tvVS = (TextView) linear.findViewById(R.id.shengfurenjiu_line_tv_vs);

			tvNum.setText(String.valueOf(i + 1));
			tvHomeTeam.setText(list.get(i).getHomeTeam());
			tvGuestTeam.setText(list.get(i).getVisiting());
			if (list.get(i).getDanMa().equals(Config.NUM0)) {
				tvDan.setText(Config.NULLMARK);
			} else if (list.get(i).getDanMa().equals(Config.NUM1)) {
				tvDan.setText("胆");
			}

			if (list.get(i).getTouZhu().equals(STAR)) {

				EDebug.o(this, "第" + i + "支队伍没有投注");
				tvState.setText(NOT_CHOOSE);
				tvNum.setTextColor(getResources().getColor(R.color.disable_text));
				tvHomeTeam.setTextColor(getResources().getColor(R.color.disable_text));
				tvGuestTeam.setTextColor(getResources().getColor(R.color.disable_text));
				tvState.setTextColor(getResources().getColor(R.color.disable_text));
				tvDan.setTextColor(getResources().getColor(R.color.disable_text));
				tvVS.setTextColor(getResources().getColor(R.color.disable_text));
			} else {
				String result = ShengFuRenJiuDetailInfo.getInfo().getOpencode();
				if (result == null || result.equals(Config.NULLMARK)) {
					tvState.setText(addComma(list.get(i).getShutin(), Config.NULLMARK));
				} else {
					String[] resultList = result.split(",");
					if (i > resultList.length) {
						tvState.setText(addComma(list.get(i).getShutin(), Config.NULLMARK));
					} else {
						tvState.setText(addComma(list.get(i).getShutin(), resultList[i]));
					}
				}
			}

			linearContent.addView(linear);

		}

	}

	private TextView tvForContentTip(String str) {

		TextView tvTip = new TextView(ShengfurenjiuRecordDetailAct.this);
		tvTip.setText(str);
		tvTip.setGravity(Gravity.CENTER);
		tvTip.setTextColor(getResources().getColor(R.color.solid_black));

		return tvTip;

	}

	/**
	 * @Title: addComma
	 * @Description: 组织用户投注信息
	 * @param: @param shotin 用户该队投注信息
	 * @param: @param result 该队开奖信息
	 * @param: @return 显示字符串
	 * @return: SpannableStringBuilder 返回类型
	 * @throws
	 */
	private SpannableStringBuilder addComma(String shotin, String result) {

		// 组织返回整体字符串
		if (shotin.length() > 1) {
			String[] temp = shotin.split(Config.NULLMARK);
			shotin = "";
			for (int i = 0; i < temp.length; i++) {
				shotin = shotin + temp[i];
				if (i != 0 && i != temp.length - 1) {
					shotin = shotin + Config.COMMA;
				}
			}
		}
		// 判断是否有选中，即与开奖一致，改变颜色
		SpannableStringBuilder sb = new SpannableStringBuilder(shotin);
		if (!result.equals(Config.NULLMARK) && shotin.contains(result)) {
			int index = shotin.indexOf(result);
			int start;
			int end;
			if (index - 1 < 0) {
				start = 0;
			} else {
				start = index - 1;
			}
			if (index + 1 > shotin.length()) {
				end = shotin.length();
			} else {
				end = index + 1;
			}
			sb.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.solid_red)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			EDebug.o(this, "有选中的比赛结果 result = " + result + " str = " + sb.subSequence(start, end));
		}

		return sb;
	}

	private void threadGetUserIcon(final String userName) {
		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					boolean isSucceed = getUserIconCommunicater.isGetIconNameSucced(userName);
					if (isSucceed) {
						Message msg = handlerHemaiDetail.obtainMessage(GET_ICONNAME_SUCCEED, null);
						handlerHemaiDetail.sendMessage(msg);
					} else {
						Message msg = handlerHemaiDetail.obtainMessage(GET_ICONNAME_FAIL, null);
						handlerHemaiDetail.sendMessage(msg);
					}
				} catch (Exception e) {
					Message msg = handlerHemaiDetail.obtainMessage(GET_ICONNAME_FAIL, null);
					handlerHemaiDetail.sendMessage(msg);
				}
			}
		}.start();
	}

	/**
	 * @Title: threadGetDetail
	 * @Description: 获取详情接口
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void threadGetDetail() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				Message msg = new Message();
				try {
					boolean isGetSucceed;
					isGetSucceed = detailCommunicater.isGetDetailSucceed(Config.SHENGFUCAI, id);
					if (isGetSucceed) {
						msg = handlerHemaiDetail.obtainMessage(GET_DETAIL_SUCCEED, null);
						handlerHemaiDetail.sendMessage(msg);
					} else {
						msg = handlerHemaiDetail.obtainMessage(GET_DETAIL_FAIL, null);
						handlerHemaiDetail.sendMessage(msg);
					}
				} catch (Exception e) {
					msg = handlerHemaiDetail.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerHemaiDetail.sendMessage(msg);
				}
			}
		}.start();
	}

	/**
	 * @Title: initData
	 * @Description: 数据初始化
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void initData() {
		Bundle bundle = this.getIntent().getExtras();
		id = bundle.getString(Key.KEY_ID);
		lotId = bundle.getString(Key.KEY_LOTID);
		uid = bundle.getString(Key.KEY_UID);
	}

	/**
	 * @Title: initUi
	 * @Description: 界面初始化
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void initUi() {

		tvTerm = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_term);
		tvTime = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_time);
		tvProId = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_programId);

		imageFaqiren = (ImageView) findViewById(R.id.shengfurenjiurecorddetailact_image_faqiren);
		tvFaqiren = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_faqiren);
		tvHitCount = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_hitCount);
		tvHitMoney = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_hitMoney);
		tvAllMoney = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_allMoney);
		tvMultiple = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_multiple);
		tvAllCount = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_allCount);
		tvEachMoney = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_eachMoney);
		tvBaodiMoney = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_baodiMoney);
		tvTicheng = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_ticheng);
		tvIssuc = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_issuc);
		tvJindu = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_jindu);
		linearContent = (LinearLayout) findViewById(R.id.shengfurenjiurecorddetailact_linear_content);

		btnCancel = (ImageButton) findViewById(R.id.shengfurenjiurecorddetailact_btn_cancel);
		btnCancel.setOnClickListener(this);
		btnCheDan = (Button) findViewById(R.id.shengfurenjiurecorddetailact_btn_cheDan);
		btnCheDan.setOnClickListener(this);

		progress = ViewerUtil.showProgressDialog(ShengfurenjiuRecordDetailAct.this, "加载中...");
		progress.show();

		linearZhanji = (LinearLayout) findViewById(R.id.shengfurenjiurecorddetailact_linear_zhanji);
		linearLayOutZhanji = (LinearLayout) findViewById(R.id.shengfurenjiurecorddetailact_ll_zhanji);

		tvLotteryState = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_lotteryState);
		tvWinMoney = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_getMoney);

		tvTitle = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_title);
		relativeOpenCode = (RelativeLayout) findViewById(R.id.shengfurenjiurecorddetailact_relative_openCode);
		tvOpenCode = (TextView) findViewById(R.id.shengfurenjiurecorddetailact_tv_openCode);

		tvTime.setText(NO_DATA);
		tvHitCount.setText(NO_DATA);
		tvHitMoney.setText(NO_DATA);
		tvAllMoney.setText(NO_DATA);
		tvMultiple.setText(NO_DATA);
		tvAllCount.setText(NO_DATA);
		tvEachMoney.setText(NO_DATA);
		tvBaodiMoney.setText(NO_DATA);
		tvTicheng.setText(NO_DATA);
		tvIssuc.setText(NO_DATA);
		tvJindu.setText(NO_DATA);
		getUserIconCommunicater = new GetUserIconCommunicater();
		detailCommunicater = new GetRenjiuShengfuRecordDetailCommunicater();
		progress.show();
		threadGetDetail();

	}

	/**
	 * 2012-3-15 kael修改 战绩计算及显示
	 * 
	 * @param strgolddiamond
	 * @param strsilverdiamond
	 * @param strgoldstar
	 * @param strsilverstar
	 * @param strgoldcup
	 */
	private void zhanJiShow(String strgolddiamond, String strsilverdiamond, String strgoldstar, String strsilverstar, String strgoldcup) {
		ShowZhanji zhanji = new ShowZhanji(ShengfurenjiuRecordDetailAct.this);
		// 获取显示战绩星级图片的list
		ArrayList<ImageView> zhanjilist = new ArrayList<ImageView>();
		zhanjilist = zhanji.showzhanji(strgolddiamond, strsilverdiamond, strgoldstar, strsilverstar, strgoldcup);
		// 判断是否有战绩
		int size = zhanjilist.size();
		if (size == 0) {// 没有战绩就不显示战绩的linear
			linearLayOutZhanji.setVisibility(View.GONE);
		} else {// 有战绩就将list中的ImageView添加到显示战绩的linear
			for (int i = 0; i < zhanjilist.size(); i++) {
				linearZhanji.addView(zhanjilist.get(i));
			}
		}
	}

	/**
	 * @Title: getAvatar
	 * @Description: 获取用户头像
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void getAvatar() {
		new Thread() {

			@Override
			public void run() {
				super.run();

				Bitmap bm = null;
				String name = HemaiDetailInfo.getHemaiDetailInfo().getUserIcon();
				ImageDB.getImageDB().open(ShengfurenjiuRecordDetailAct.this);

				bm = ImageUtils.getLocalImg(name);

				if (bm == null) {
					bm = ImageUtils.downLoadImg(name);
					if (bm != null) {
						Message msg = handlerHemaiDetail.obtainMessage(REPLACE_IMAGE, bm);
						handlerHemaiDetail.sendMessage(msg);
						ImageUtils.saveImg(name, bm);
					}
				} else {
					Message msg = handlerHemaiDetail.obtainMessage(REPLACE_IMAGE, bm);
					handlerHemaiDetail.sendMessage(msg);
				}
				ImageDB.getImageDB().close();
			}
		}.start();
	}

	// 撤单按钮点击事件
	private void btnChenDanOnClick() {
		final Dialog chenDanDialog = new Dialog(ShengfurenjiuRecordDetailAct.this, R.style.dialog);
		chenDanDialog.getWindow().setContentView(R.layout.dialog_doublebutton_lotteryrecord_detail);
		TextView tvChenDanMsg = (TextView) chenDanDialog.getWindow().findViewById(R.id.dialog_doublebutton_tv_msg);
		tvChenDanMsg.setText(Language.MSG_REMOVE_SURE);
		Button btnChenDanYes = (Button) chenDanDialog.getWindow().findViewById(R.id.dialog_doublebutton_btn_yes);
		btnChenDanYes.setText(getResources().getString(R.string.ok));
		btnChenDanYes.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				cheDanThread();
				chenDanDialog.dismiss();
				progress = ViewerUtil.showProgressDialog(ShengfurenjiuRecordDetailAct.this, Language.MSG_CHEDANING);
			}
		});
		Button btnChenDanNo = (Button) chenDanDialog.getWindow().findViewById(R.id.dialog_doublebutton_btn_no);
		btnChenDanNo.setText(getResources().getString(R.string.cancel));
		btnChenDanNo.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				chenDanDialog.dismiss();
			}
		});
		chenDanDialog.show();
	}

	// 撤单通讯线程
	private void cheDanThread() {
		new Thread() {
			@Override
			public void run() {
				if (cheDanCommunicater == null) {
					cheDanCommunicater = new CheDanCommunicater();
				}
				EDebug.o(this, "进入撤单线程");
				Message msg;
				try {
					boolean isSucceed;
					EDebug.o(this, "发起人：" + strfaqiren + "用户：" + UserInfo.getUserInfo().getUserName());
					if (UserInfo.getUserInfo().getUserName().equals(strfaqiren)) {
						EDebug.o(this, "发起人撤单");
						isSucceed = cheDanCommunicater.userOrderCheDan(lotId, id, playId);
					} else {
						EDebug.o(this, "跟单人撤单");
						isSucceed = cheDanCommunicater.isCheDan(lotId, uid, playId);
					}
					if (isSucceed) {
						msg = handlerHemaiDetail.obtainMessage(CHEDAN_SUCCEED, cheDanCommunicater.getServerMsg());
					} else {
						msg = handlerHemaiDetail.obtainMessage(CHEDAN_FAIL, cheDanCommunicater.getServerMsg());
					}
					handlerHemaiDetail.sendMessage(msg);
				} catch (Exception e) {
					msg = handlerHemaiDetail.obtainMessage(Config.CONNECTION_FAIL);
					handlerHemaiDetail.sendMessage(msg);
				}
			}
		}.start();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.shengfurenjiurecorddetailact_btn_cancel:
			ShengfurenjiuRecordDetailAct.this.finish();
			break;

		case R.id.shengfurenjiurecorddetailact_btn_cheDan:
			btnChenDanOnClick();
			break;

		default:
			break;
		}

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	@Override
	protected void onResume() {
		super.onResume();
		OptionAct.isLoginSucceed = false;
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());
	}

}
